import axios from "@/api/config"
//系统右上角下拉树操作接口 开始
export const userOpt = {
    userDetail: async () => {//获取当前用户基本信息详情
        const url = '/ssm/user/current';
        let res = await axios.get(url);
        return res;
    },
    //修改密码
    updatePassword: async (data) => {
        const url = '/ssm/user/update/password?oldPassword='+data.oldPassword+'&newPassword='+data.newPassword;
        let res = await axios.get(url);
        return res;
    },
    //设置默认部门
    setDefaultUnit: async (data) => {
        const url = '/ssm/user/default/unit/'+data;
        let res = await axios.put(url);
        return res;
    },
    //切换
    switchUnit: async (data) => {//获取当前用户基本信息详情
        const url = '/sso/system/switch/unit?unitId='+data;
        let res = await axios.get(url);
        return res;
    },
    //修改个人信息
    updateInform: data=>axios.put('/ssm/user/update/info',data)
}
//系统右上角下拉树操作接口 结束
//角色管理开始
export const getRoleList = data => axios.post('ssm/role/page', data)  //获取角色列表
export const addRole = data => axios.post('ssm/role/add', data)  //获取角色列表
export async function deleteRole(id) { //删除角色
    const url = 'ssm/role/delete/' + id;
    const res = await axios.delete(url);
    return res;
}
export async function updateRole(data) { //更新角色信息
    const url = 'ssm/role/update/';
    const res = await axios.put(url,data);
    return res;
}
export async function getRoleData(id) { //删除角色
    const url = 'ssm/role/' + id;
    const res = await axios.get(url);
    return res;
}
export async function autRoleData(id) { //角色权限
    const url = '/ssm/role/grant/' + id;
    const res = await axios.get(url);
    return res;
}
export const saveAutRoleData = data => axios.post('/ssm/role/grant', data)  //角色授权
export async function roleRootData() { //获取当前独立机构下所有角色
    const res = await axios.get('/ssm/role/root/list');
    return res;
}
//角色管理结束



//用户管理开始
export const getUserList = data => axios.post('ssm/user/page', data)  //获取角色列表
export const addUser = data => axios.post('ssm/user/add', data)  //新增角色
export async function getUser(id) { //获取用户信息
    const url = 'ssm/user/'+ id;
    const res = await axios.get(url);
    return res;
}
export async function updateUser(data) { //编辑用户
    const url = 'ssm/user/update';
    const res = await axios.put(url,data);
    return res;
}
export async function deleteUser(id) { //删除用户
    const url = 'ssm/user/delete/' + id;
    const res = await axios.delete(url);
    return res;
}
export async function disableUser(id) { //禁用用户
    const url = 'ssm/user/disable/' + id;
    const res = await axios.put(url);
    return res;
}
export async function enableUser(id) { //启用用户
    const url = 'ssm/user/enable/' + id;
    const res = await axios.put(url);
    return res;
}
export async function resetUser(id) { //重置密码
    const url = 'ssm/user/password/reset/' + id;
    const res = await axios.put(url);
    return res;
}
export async function grantUser(data) { //用户授权
    const url = 'ssm/user/grant';
    const res = await axios.put(url,data);
    return res;
}
//用户管理结束



// 职位开始
export const getDutyList = data => axios.post('/ssm/duty/role/page', data)  //获取角色列表
export const addDuty = data => axios.post('/ssm/duty/role/add', data)  //新增职位列表
export async function deleteDuty(id) { //删除职位
    const url = '/ssm/duty/role/delete/' + id;
    const res = await axios.delete(url);
    return res;
}
export async function putDuty(data) { //授权职位
    const url = '/ssm/duty/role/grant' ;
    const res = await axios.put(url,data);
    return res;
}
export async function getDutyDet(id) { //授权详情
    const url = '/ssm/duty/role/grant/' + id;
    const res = await axios.get(url);
    return res;
}
export async function upDuty(data) { //编辑
    const url = '/ssm/duty/role/update' ;
    const res = await axios.put(url,data);
    return res;
}
export async function detDuty(id) { //详情
    const url = '/ssm/duty/role/' + id;
    const res = await axios.get(url);
    return res;
}
// 职位结束



// 工作组开始
export const getTeamList = data => axios.post('/ssm/team/list', data)  //获取角色列表
export async function deleteWorks(id) { //删除用户
    const url = '/ssm/team/delete/' + id;
    const res = await axios.delete(url);
    return res;
}
export async function getWorkDetail(id) { //部门详情
    const url = '/ssm/team/' + id;
    const res = await axios.get(url);
    return res;
}
export async function upWork(data) { //编辑
    const url = '/ssm/team/update' ;
    const res = await axios.put(url,data);
    return res;
}
export const addWork = data => axios.post('/ssm/team/add', data)  //新增部门
// 工作组结束


// 部门管理开始
// export async function getUnitList(id) { //部门列表
//     const url = 'ssm/unit/tree/list' + id;
//     const res = await axios.get(url);
//     return res;
// }
export const addUnit = data => axios.post('/ssm/unit/add', data)  //新增部门

export async function deleteUnit(id) { //删除部门
    const url = '/ssm/unit/delete/' + id;
    const res = await axios.delete(url);
    return res;
}

export async function upUnit(data) { //编辑
    const url = '/ssm/unit/update' ;
    const res = await axios.put(url,data);
    return res;
}

export async function getUnit(id) { //部门详情
    const url = '/ssm/unit/' + id;
    const res = await axios.get(url);
    return res;
}

export async function getUnitUser(id) { //部门获取组织机构/部门下用户数据
    const url = '/ssm/unit/user/' + id;
    const res = await axios.get(url);
    return res;
}
export async function upDateUser(data) { //编辑
    const url = '/ssm/unit/user/'+data;
    const res = await axios.put(url);
    return res;
}
// 部门管理结束